package transform.email;

import data.Term;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import transform.Stopper;

/**
 * EmailStopper membuang term berupa stop words dari dalam koleksi term
 * @author Robert Gunawan
 */
public class EmailStopper implements Stopper {

    /**
     * kamus stop words
     */
    private static String stopWordsArray[] = {"a", "about", "above", "after",
        "again", "against", "all", "am", "an", "and", "any", "are", "arent",
        "as", "at", "be", "because", "been", "because", "been", "before", "being",
        "below", "between", "both", "but", "by", "cant", "cannot", "could", "did",
        "didnt", "do", "does", "doesnt", "doing", "down", "during", "each", "few",
        "for", "from", "from:", "further", "fw:", "had", "hadnt", "has", "hasnt", "have", "havent",
        "having", "he", "hed", "hell", "hes", "her", "here", "heres", "hers", "herself",
        "him", "himself", "his", "how", "hows", "http:", "https:", "i", "id", "ill", "im", "ive",
        "if", "in", "into", "is", "isnt", "it", "its", "its", "itself", "lets", "me", "more",
        "most", "mustnt", "my", "myself", "no", "nor", "not", "of", "off", "on", "once",
        "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "re:",
        "same", "shant", "she", "shed", "shell", "shes", "should", "shouldnt",
        "so", "some", "such", "than", "that", "thats", "the", "their", "theirs",
        "them", "themselves", "then", "there", "theres", "these", "they", "theyd",
        "theyll", "theyre", "theyve", "this", "those", "through", "to", "to:", "too",
        "under", "until", "up", "very", "was", "wasnt", "wed", "well", "weve",
        "were", "were", "werent", "what", "whats", "when", "whens", "where",
        "wheres", "which", "while", "who", "whos", "whom", "why", "whys", "with",
        "wont", "would", "wouldnt", "www", "you", "youd", "youll", "youre", "youve",
        "your", "yours", "yourself", "yourselves"};
    /**
     * array stop words hasil konversi kamus stop words
     */
    private ArrayList<String> stopWords;
    /**
     * konstruktor EmailStoppper
     */
    public EmailStopper() {
        stopWords = new ArrayList<String>();
        stopWords.addAll(Arrays.asList(stopWordsArray));
    }

    @Override
    public HashMap<String, Term> doStop(HashMap<String, Term> term) {
        HashMap<String, Term> result = new HashMap<String, Term>();
        Iterator it = term.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pairs = (Map.Entry) it.next();
            Term checkedTerm = (Term) pairs.getValue();
            if (!stopWords.contains(checkedTerm.getTermString()) && (checkedTerm.getTermString().length() <= Term.max_term_length) && (checkedTerm.getTermString().length() > 2)) {
                result.put(checkedTerm.getTermString(), checkedTerm);
            }
        }
        return result;
    }
}
